/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * <p>Project: jse2303 - Stream2</p>
 * <p>Powered by webrx On 2023-07-25 14:28:56</p>
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Stream2 {

    public static double rand() {
        return Math.random();
    }

    public double rands() {
        return Math.random();
    }

    public static void main(String[] args) {
        //建立流
        IntStream s1 = IntStream.range(1, 6);

        //DoubleStream.generate(() -> Math.random()).limit(10).forEach(System.out::println);


        //DoubleStream.generate(Math::random).limit(10).forEach(e -> System.out.printf("%.2f%n", e));


        //DoubleStream.generate(Stream2::rand).limit(10).forEach(e -> System.out.printf("%.2f%n", e));

        var s = new Stream2();

        DoubleStream.generate(s::rands).limit(10).forEach(e -> System.out.printf("%.2f%n", e));

        IntStream is3 = IntStream.range(1, 5); //1 2 3 4
        //System.out.println(is3.count());
        System.out.println(is3.sum());


        //s1 = s1.map(e -> e + 10);

        //System.out.println(s1.count());

        //s1.forEach(System.out::println);


        Stream<String> s2 = Stream.of("a", "b", "c");
        s2.parallel().forEach(System.out::println);
    }
}
